package com.addressbook.tests;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;

import java.util.logging.Logger;

import org.testng.annotations.Test;

import com.addressbook.fw.Groups;

public class TestGroupCreation extends TestBase {
	
	private Logger log = Logger.getLogger("TestGroupCreation");

	@Test(dataProvider = "groupsFromFile", dataProviderClass = GroupDataGenerator.class)
	public void testValidGroupCanBeCreated(GroupObject validGroup)
			throws Exception {
		log.info("testValidGroupCanBeCreated() started");
		Groups oldList = app.getGroupHelper().getGroups();
		log.info("List before test: " + oldList);
		app.getGroupHelper().createGroup(validGroup);
		log.info("Group added: " + validGroup);
		Groups newList = app.getGroupHelper().getGroups();
		log.info("List after test: " + newList);
		assertThat(newList, equalTo(oldList.withAdded(validGroup)));
//		verifyGroupAdded(oldList, validGroup, newList);
		log.info("testValidGroupCanBeCreated() finished");
	}

//	private void verifyGroupAdded(Set<GroupObject> oldList,
//			GroupObject validGroup, Set<GroupObject> newList) {
//		validGroup.setId("$$$");
//		oldList.add(validGroup);
//		validGroup.setId(null);
//		assertThat(newList, equalTo(oldList));
//	}

//	@Test
	public void testEmptyGroup() throws Exception {
		GroupObject emptyGroup = new GroupObject().setName("").setFooter("")
				.setFooter("");
		app.getGroupHelper().createGroup(emptyGroup);
	}
}
